package racetrack

class User {
	
	String login
	String password
	String role = "user"

    static constraints = {
		login(blank:false, nullable:false, unique:true)
		password(blank:false, password:true)
		role(inList:["admin", "user"])
    }
	
	def beforeInsert = {
		password = password.encodeAsSHA();
	}
	
	//Fields that should not be persisted.
	static transients = ['admin']
	
	String toString(){
		login
	}
	
	//called by user.admin - like <g:if test="\${session?.user?.admin}">
	boolean isAdmin(){
		return role == "admin"
	}
}
